<?php
	abstract class IMDB_Page {
		
		// const REGEX_IMG = '#<img src="(.*?)" width="23" height="32" border="0">#i';
		// const REGEX_URL = "#/(.*?)/(.*?)/#i";
		
		const REGEX_TVSERIES = '#<span class="tv-extra">TV Series (.*?)</span>#i';
		const REGEX_TVEPISODE = '#<h5>TV Series:</h5>#i';
		protected $_iID;
		protected $_sPageURL;
		protected $_iType;
		protected $_sPageDisplay;
		protected $_aPageResults;

		public function getResults() {
			return $this->_aPageResults;
		}
		
		public function __construct($iID, $iType) {
			$this->_iID = $iID;
			$this->_iType = $iType;
			$this->_sPageDisplay = IMDB::$ENUM_PAGE_TYPE[$this->_iType];
			$this->_sPageURL = sprintf(IMDB::URL_PAGE, $this->_iID);
			$this->start();
		}
		private function start() {
			$sRawContent = file_get_contents($this->_sPageURL);
			$sRawContent = $this->preParse($sRawContent);
			$this->parse($sRawContent);
		}
		protected function getPageType($sInput) { // Not sure if I can use this somewhere... automatic _iType detection
			if(preg_match($this->REGEX_TVSERIES, $sInput)) {
				// TV Series
				return 1;
			} elseif(preg_match($this->REGEX_TVEPISODE, $sInput)) {
				// Episode
				return 2;
			} else {
				// Movie
				return 3;
			}
		}
		private function preParse($sInput) {
			$Start = '<div id="tn15title">';
			$Start = stripos($sInput, $Start);
			$sInput = substr($sInput, $Start);
			
			$End = '<div class="comment">';
			$End = stripos($sInput, $End);
			$sInput = substr($sInput, 0, $End);
			
			return $sInput;
		}
		abstract protected function parse($sInput);
	}
?>